package org.awa.demo.opencv.demo;

import org.opencv.core.Mat;
import org.opencv.core.MatOfPoint;
import org.opencv.core.Size;
import org.opencv.imgcodecs.Imgcodecs;
import org.opencv.imgproc.Imgproc;
import org.opencv.objdetect.CascadeClassifier;

import java.util.ArrayList;
import java.util.List;

/**
 * @author xxf
 */
public class CandyDetection {

    //人脸模型xml文件路径
    private static final String FACE_MODEL_PATH = "src/main/opencv/model/haarcascade_frontalface_alt.xml";
    //测试图片文件夹路径
    private static final String TRAINING_DATA_DIR = "src/main/opencv/input";
    //检测并处理后保存图片路径
    private static final String DETECTION_RESULT ="src/main/opencv/output";

    static {
        System.load("D:\\workspace\\open-cv\\open-cv\\src\\main\\resources\\libs\\opencv_java481.dll");
    }

    /**
     * 读取文件
     *
     * @param fileName
     * @return
     */
    private static Mat readImg(String fileName){
        Mat image = Imgcodecs.imread(TRAINING_DATA_DIR+"/tangdun.jpg",Imgcodecs.IMREAD_COLOR);
        return image;
    }

    /**
     * 高斯模糊
     *
     * @param src
     * @return
     */
    private static Mat gaussianBlur(Mat src){
        Mat dist = new Mat();
        Imgproc.GaussianBlur(src,dist,new Size(5,5),10);
        return dist;
    }

    /**
     * 灰度处理
     *
     * @param src
     * @return
     */
    private static Mat grayProcession(Mat src){
        Mat dist = new Mat();
        Imgproc.cvtColor(src,dist,Imgproc.COLOR_BGR2GRAY);
        return dist;
    }

    /**
     * 二值化处理
     *
     * @param src
     * @return
     */
    private static Mat thresholdProcession(Mat src,double threshold){
        Mat dist = new Mat();
        Imgproc.threshold(src,dist,threshold,255,Imgproc.THRESH_BINARY);
        return dist;
    }

    /**
     * 轮廓识别
     *
     * @param src
     * @return
     */
    private static List<MatOfPoint> candy(Mat src){
        List<MatOfPoint> dist = new ArrayList<>();
        Imgproc.findContours(src,dist,null,Imgproc.RETR_TREE,Imgproc.CHAIN_APPROX_NONE);
        return dist;
    }

    private static void draw(){

    }


}
